package com.jp.study.config;

import javax.annotation.PostConstruct;

import org.aopalliance.aop.Advice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import com.jp.study.Interceptor.LogMethodInterceptor;
import com.jp.study.annotation.LogSpendTime;
import com.jp.study.properties.method2time.JPMethodExecutionTimeLogProperties;

/**
 * 
* @author dinghao
* @ClassName: LogAutoConfiguration 
* @Description: 计算方法执行时间的配置类
* @date 2018年3月21日 上午10:32:13 
*
 */

@Configuration
@EnableConfigurationProperties(JPMethodExecutionTimeLogProperties.class)
public class LogAutoConfiguration extends DefaultPointcutAdvisor{

	private static final long serialVersionUID = 1L;

	private Logger logger = LoggerFactory.getLogger(LogAutoConfiguration.class);

    private Pointcut pointcut;

    private Advice advice;

    @Autowired
    private JPMethodExecutionTimeLogProperties logProperties;

    @PostConstruct
    public void init() {
        logger.info("init LogAutoConfiguration start");
        this.pointcut = new AnnotationMatchingPointcut(null, LogSpendTime.class);
        this.advice = new LogMethodInterceptor(logProperties.getExcludeArr());
        logger.info("init LogAutoConfiguration end");
    }

    @Override
    public Pointcut getPointcut() {
        return this.pointcut;
    }

    @Override
    public Advice getAdvice() {
        return this.advice;
    }

}